package com.zoroki.student_score_system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zoroki.student_score_system.domain.Course;
import com.zoroki.student_score_system.service.CourseService;
import com.zoroki.student_score_system.mapper.CourseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【course】的数据库操作Service实现
* @createDate 2025-06-30 12:49:22
*/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course>
    implements CourseService{
    @Autowired
    private CourseMapper courseMapper;


    @Override
    public List<Course> findAllCourses() {
        return courseMapper.selectList(null);
    }

    @Override
    public Course findCourseById(int id) {
        return courseMapper.selectById(id);
    }
    @Override
    public Course getCourseByName(String name) {
        QueryWrapper<Course> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        return courseMapper.selectOne(queryWrapper);
    }

    @Override
    public boolean addCourse(Course course) {
        return courseMapper.insert(course) == 1;
    }

    @Override
    public boolean updateCourse(Course course) {
        return courseMapper.updateById(course) == 1;
    }

    @Override
    public boolean deleteCourse(int id) {
        return courseMapper.deleteById(id) == 1;
    }


}




